'use strict'
const config = require('config')
const koaTool = require('../../commons/koa_tool')
const admin_auth_service = require('../services/admin_auth')

const _const = require('../../commons/const')
const {
    SupplyModel,
    BuyRecordModel
} = require('../../models')
const passwordUtility = require('../../commons/password_utility')


module.exports = {
    async test(ctx) {
        let postData = ctx.request.body
        return {
            postData
        }
    },
    async getSupplyListInfo(ctx) {
        //列表
            let [checkError, input] = koaTool.checkInput(ctx, [])
            if (checkError) {
                return koaTool.fail(ctx, checkError)
            }
            let query = {}
            let list = await BuyRecordModel.find(query).sort([['order', 1]]);
            koaTool.succ(ctx, list)
    },
    async addSupplier(ctx) {
        const supply = { "name": "esp32", "price": "30" };
        let supplyRes = await SupplyModel.create(supply)
        return koaTool.success(ctx, '创建成功');
    },
    async addBuyRecord(ctx) {
        let [checkError, input] = koaTool.checkInput(ctx, ['name', 'price', 'url','description','phone','contact'])
        if (checkError) {
            return koaTool.fail(ctx, checkError)
        }
        let newData = Object.assign({}, input, {
        })
        // console.log("newdata",newData)
        let res = await BuyRecordModel.create(newData)
       //  console.log("res",res)
        return koaTool.success(ctx, '创建成功');
    }
}
